package sctu.edu.java.year2016.team02.luoxi.day20160602.Chapter9_1;

import java.util.Scanner;

/**
 * Created by 小可爱罗希 on 2016/6/1.
 * 编写Java程序，创建一个类，并在类中创建一个成员内部类，通过成员内部类计算1到任意数的和的操作，并在外部类中进行测试。
 */
public class SumOfRank {

    private int Rank;

    private class SumOf {
        int Sum = 0;

        int theWay(int Rank) {
            if (Rank == 1) {
                return Sum += 1;
            }
            else {
                Sum += Rank;
                return theWay(Rank - 1);
            }
        }
    }

    void getSumOf() {
        SumOf rank = new SumOf();
        System.out.println("Answer is:"+rank.theWay(Rank));
    }

    public void setRank(int rank) {
        Rank = rank;
    }

    public static void main(String[] args) {
        System.out.print("Set the Rank:");

        SumOfRank rank = new SumOfRank();
        Scanner scan = new Scanner(System.in);
        rank.setRank(scan.nextInt());
        rank.getSumOf();
    }

}
